/*******************************************************************
 * 外语翻译平台(translate) 
 *
 * 成都一亿信息技术公司 版权所有
 * 
 * Copyright (C) 2010 Transer Information Technology Co., Ltd.
 *
 * @Version : 1.0  2011-1-8 下午04:08:50
 *
 * chooselanguage.js 
 *
 *******************************************************************/
var Translate = [{"id":20001,"name":"中文"},
                 {"id":20002,"name":"英语"},
                 {"id":20003,"name":"法语"},
                 {"id":20004,"name":"德语"},
                 {"id":20005,"name":"韩语"},
                 {"id":20006,"name":"日语"},
                 {"id":20007,"name":"俄语"},
                 {"id":20008,"name":"泰语"},
                 {"id":20009,"name":"越南语"},
                 {"id":20010,"name":"拉丁语"},
                 {"id":20011,"name":"意大利语"},
                 {"id":20012,"name":"阿拉伯语"},
                 {"id":20013,"name":"葡萄牙语"},
                 {"id":20014,"name":"西班牙语"},
                 {"id":20015,"name":"其他语言"}];

var translateType = [
				{"id":30001,"name":"笔译"},
				{"id":30002,"name":"口译"},
				{"id":30003,"name":"检查/编辑"},
				{"id":30004,"name":"转录"}
                     ];

function getTranslate(id) {
	id = parseInt(id);
	for (var i = 0 ; i < Translate.length ; i ++) {
		if (id == Translate[i].id) {
			return Translate[i].name;
		}
	}
}

function getTranslateType(id) {
	id = parseInt(id);
	for (var i = 0 ; i < translateType.length ; i ++) {
		if (id == translateType[i].id) {
			return translateType[i];
		}
	}	
}

function initLanguage(id, val) {
	var obj = $("#"+id);
	var fragement = new Array();
	var data = Translate;
	
	for (var index = 0 ; index < data.length ; index ++) {
		if (val == "" + data[index].id) {
			fragement.push("<option value='" + data[index].id + "' selected='selected'>" + data[index].name + "</option>");				
		} else {
			fragement.push("<option value='" + data[index].id + "'>" + data[index].name + "</option>");
		}
	}
	obj.append(fragement.join(""));
}

function selectall(obj) {
	try {
		$(obj).parent().parent().find("input:checkbox").each(function (index, obj){
			$(this).attr('checked', true);
		});
	} catch (e) {
		alert(e);
	}
}

function diselectall(obj) {
	$(obj).parent().parent().find("input:checked").each(function (index, obj){
		$(this).attr('checked', false);
	});
}

function ChooseLanguageWindow() {
	this.op = {
			resizable:false, 
			modal:true, 
			width:'auto'
		};
	
	this.content = '<div id="lang" style="font-size:12px;" title="请选择你所擅长的语言">';
	this.content += '<div style="width:100%;text-align:right;"><a style="cursor: pointer;" onclick="javascript:selectall(this)">全选</a> <a style="cursor: pointer;" onclick="javascript:diselectall(this)">全不选</a></div>';
	
	for (var index = 0; index < Translate.length ; index ++) {
		if (index % 5 == 0) {
			this.content += '<dl><dd>';
		} 
		this.content += '<input type="checkbox" value="'+Translate[index].id+'" /><span>'+Translate[index].name+'</span>';
		if ((index + 1) % 5 == 0) {
			this.content += '</dd></dl>';
		}
	}
	this.content += '</div>';
	
	$(this.content).dialog({
		autoOpen: false,
		show: "blind",
		hide: "explode"
	});
}

ChooseLanguageWindow.prototype.show = function (callback) {
	if (typeof opt == 'function') {
		return;
	}
	
	document.callback = callback;
	
	this.op.buttons = {
		'确定':function () {
			document.callback(this, selectCheckbox(this));
			close(this);
		},
		'取消':function () {
			close(this);
		}
	};
	
	$(this.content).dialog(this.op);
	
	$(this.content).dialog('open');
};

function selectCheckbox(newobj) {
	var sels = [];
	$(newobj).find('input:checked').each(function (index, obj){
		var sel = {};
		sel.id = $(obj).val();
		sel.txt = $(obj).next('span').text();
		sels.push(sel);
	});
	return sels;
};

function close(newobj) {
	$(newobj).dialog("close");
};